import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

let actions = {
	jiaOdd(miniStore,number){
		if(miniStore.state.sum % 2){
			miniStore.commit('JIA',number)
		}
	},
	jiaServer(miniStore){
		axios.get('https://api.uixsj.cn/hitokoto/get?type=social').then(
			response => {
				alert(response.data)
				miniStore.commit('JIA',response.data.length)
			},
			error => {
				alert(error)
			}
		)
	},
	jiaRen(miniStore,personObj){
		miniStore.commit('JIA_REN',personObj)
	}
}

let mutations = {
	JIA(state,value){
		state.sum += value
	},
	JIAN(state,value){
		state.sum -= value
	},
	JIA_REN(state,personObj){
		state.persons.unshift(personObj)
	}
}

let state = {
	sum:1,
	persons:[
		{id:'g67f78',name:'张三'},
		{id:'u879u2',name:'李四'},
		{id:'0u098y',name:'晶晶'},
	]
}

let getters = {}

export default new Vuex.Store({
	actions,
	mutations,
	state,
	getters
})